SECKILL_URL = "http://seckill.com:8080";
RESULT_OK = 0;
RESULT_FAIL = 1;
TOKEN_EXPIRE = 2;

// 后台-查询商品信息
// 后台-管理秒杀活动（创建活动、开始活动、结束活动）
// 秒杀流程：商品详情页（立即抢购）-> 结算页(提交订单) -> 支付页/抢购失败页
// 商品详情页根据商品标识展示普通商品或秒杀商品
PAGE = {
    product: SECKILL_URL + "/product", // 后台-查询商品信息，不属于秒杀系统
    activity: SECKILL_URL + "/activity", // 后台-管理秒杀活动，不属于秒杀系统，属于运营系统
    buy: SECKILL_URL + "/buy", // 商品详情页，不属于秒杀系统
    settlement: SECKILL_URL + "/settlement", // 结算页，属于秒杀系统
    pay: SECKILL_URL + "/pay", // 支付页，不秒杀系统
    fail: SECKILL_URL + "/fail", // 抢购失败页，不属于秒杀系统
}

API = {
    productData: SECKILL_URL + "/product/productData", // 查询商品数据
    activityData: SECKILL_URL + "/activity/activityData", // 查询活动数据
    createActivity: SECKILL_URL + "/activity/createActivity", // 创建活动
    startActivity: SECKILL_URL + "/activity/startActivity", // 开始活动
    endActivity: SECKILL_URL + "/activity/endActivity", // 结束活动
    settlementToken: SECKILL_URL + "/settlement/token", // 结算页 token
    submitOrder: SECKILL_URL + "/settlement/submitOrder", // 提交订单
}


function getParameterByName(name, url = window.location.href) {
    name = name.replace(/[\[\]]/g, '\\$&');
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

function get(url, params, callback) {
    axios.get(url, {params: params, validateStatus: validateStatus}).then(function(resp){
        callback(resp.data, resp.headers, resp.status)
    });
}

function post(url, params, callback) {
    axios.post(url, params, {validateStatus: validateStatus}).then(function(resp){
        callback(resp.data, resp.headers, resp.status)
    });
}

function validateStatus(status) {
    return (status >= 200 && status < 300) || status == 403;
}
function redirect(url, params) {
    location.href = getUrl(url, params);
}

function getUrl(url, params) {
    if (params == undefined || params == null || params == {}) {
        return url;
    }
    let paramsStr = "";
    let first = true;
    for (name in params) {
        if (first) {
            paramsStr += "?";
            first = false;
        } else {
            paramsStr += "&"
        }
        paramsStr += name + "=" + params[name];
    }
    return url + paramsStr;
}
